package com.nutricia.biz.convertor;

import com.nutricia.common.api.info.SystemPermissionInfo;
import com.nutricia.core.model.domain.SystemPermissionDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 系统权限对象转换器
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemPermissionConvertor {

   /**
    * 将 SystemPermissionDO 转换为 SystemPermissionInfo
    *
    * @author: huangsheng
    * @date: 2017/10/24 上午10:48
    */
    public static SystemPermissionInfo convertToSystemPermissionDO(final SystemPermissionDO systemPermissionDO) {
        if (null == systemPermissionDO) {
            return null;
        }
        SystemPermissionInfo systemPermissionInfo = new SystemPermissionInfo();
        systemPermissionInfo.setPermissionId(systemPermissionDO.getId());
        systemPermissionInfo.setPermissionName(systemPermissionDO.getPermissionName());
        systemPermissionInfo.setPermissionCode(systemPermissionDO.getPermissionCode());
        return systemPermissionInfo;
    }

    /**
     * 将 SystemPermissionDOs 转换为 SystemPermissionInfos
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemPermissionInfo> convertToSystemPermissionInfoss(final List<SystemPermissionDO> systemPermissionDOS) {
        List<SystemPermissionInfo> systemPermissionInfos = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemPermissionDOS)) {
            systemPermissionDOS.forEach(systemPermissionDO -> {
                systemPermissionInfos.add(SystemPermissionConvertor.convertToSystemPermissionDO(systemPermissionDO));
            });
            return systemPermissionInfos;
        }
        return Collections.emptyList();
    }

}
